package data

import (
	"context"
	"gorm.io/gorm/clause"
	"hellorockscache/internal/biz"
)

func (g *greeterRepo) BatchCreateStudentCourses(ctx context.Context, scs []*biz.StudentCourse) error {

	db := g.data.Mysql.Table(biz.StudentCourseTableName).WithContext(ctx)
	db.CreateBatchSize = biz.BatchCreateSize

	// Notice 看实际的业务情况
	// 唯一索引冲突 修改 is_del 字段
	err := db.Clauses(clause.OnConflict{
		Columns: []clause.Column{{Name: "student_id"}, {Name: "course_id"}},
		DoUpdates: clause.Assignments(map[string]interface{}{
			"is_del": biz.SCModelNotDeleted,
		}),
	}).Create(&scs).Error

	return err
}
